home *** CD-ROM | disk | FTP | other *** search
/ Your Web Site Creator / Your Web Site Creator.iso / WebSite / data1.cab / Program_Executable_Files / Classes / KRCANVA2.CLA (.txt) < prev    next >
Encoding:
Java Class File  |  1999-01-13  |  4.8 KB  |  238 lines

  1. import java.applet.Applet;
  2. import java.awt.Canvas;
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Dimension;
  6. import java.awt.Graphics;
  7. import java.awt.Image;
  8. import java.awt.image.ImageObserver;
  9.  
  10. class KRCanvas2 extends Canvas implements Runnable {
  11.    Thread theThread;
  12.    int[] currentX;
  13.    int[] currentY;
  14.    int[] direction;
  15.    int increment;
  16.    int delay;
  17.    int numSegments;
  18.    Color theColor;
  19.    Image osImage;
  20.    Graphics osg;
  21.    int red;
  22.    int green;
  23.    int blue;
  24.    int redStep;
  25.    int greenStep;
  26.    int blueStep;
  27.    // $FF: renamed from: i int
  28.    int field_0;
  29.    Color[] colors;
  30.    int blockSpacing = 1;
  31.    boolean showCircles;
  32.    boolean sineCalc;
  33.    int mode;
  34.    int blockWidth;
  35.    int blockHeight;
  36.    static final int MODE_EAST_WEST = 0;
  37.    static final int MODE_SOUTH_NORTH = 1;
  38.    Color bkColor;
  39.    Image bkImage;
  40.  
  41.    public KRCanvas2(Applet var1, int var2) {
  42.       this.GetParameters(var1, var2);
  43.    }
  44.  
  45.    void GetParameters(Applet var1, int var2) {
  46.       String var3 = var1.getParameter("krBlockSpacing" + var2);
  47.       this.blockSpacing = AppletParam2.GetInt(var3, 1);
  48.       var3 = var1.getParameter("krSpeed" + var2);
  49.       this.delay = AppletParam2.GetInt(var3, 100);
  50.       var3 = var1.getParameter("krNumSegments" + var2);
  51.       this.numSegments = AppletParam2.GetInt(var3, 5);
  52.       var3 = var1.getParameter("krColor" + var2);
  53.       this.theColor = AppletParam2.GetColor(var3, Color.red);
  54.       var3 = var1.getParameter("krShowCircles" + var2);
  55.       this.showCircles = AppletParam2.GetBoolean(var3, false);
  56.       var3 = var1.getParameter("krSineCalc" + var2);
  57.       this.sineCalc = AppletParam2.GetBoolean(var3, true);
  58.       var3 = var1.getParameter("krUpDown" + var2);
  59.       if (AppletParam2.GetBoolean(var3, false)) {
  60.          this.mode = 1;
  61.       } else {
  62.          this.mode = 0;
  63.       }
  64.  
  65.       var3 = var1.getParameter("krBlockSize" + var2);
  66.       int var4 = AppletParam2.GetInt(var3, 10);
  67.       if (this.mode == 0) {
  68.          this.blockWidth = var4;
  69.       } else {
  70.          this.blockHeight = var4;
  71.       }
  72.  
  73.       var3 = var1.getParameter("krBkColor" + var2);
  74.       this.bkColor = AppletParam2.GetColor(var3, Color.black);
  75.       ((Component)this).setBackground(this.bkColor);
  76.       var3 = var1.getParameter("krBkImage" + var2);
  77.       this.bkImage = var1.getImage(var1.getCodeBase(), var3);
  78.    }
  79.  
  80.    public void Start() {
  81.       this.theThread = new Thread(this);
  82.       this.theThread.start();
  83.    }
  84.  
  85.    public void Stop() {
  86.       this.theThread.stop();
  87.       this.theThread = null;
  88.    }
  89.  
  90.    public void update(Graphics var1) {
  91.       if (this.osImage == null) {
  92.          this.osImage = ((Component)this).createImage(((Component)this).size().width, ((Component)this).size().height);
  93.          this.osg = this.osImage.getGraphics();
  94.       }
  95.  
  96.       this.osg.setColor(((Component)this).getBackground());
  97.       this.osg.fillRect(0, 0, ((Component)this).size().width, ((Component)this).size().height);
  98.       if (this.bkImage != null) {
  99.          int var2 = this.bkImage.getWidth(this);
  100.          int var3 = this.bkImage.getHeight(this);
  101.          int var4 = ((Component)this).size().width / var2;
  102.          int var5 = ((Component)this).size().height / var3;
  103.          ++var4;
  104.          ++var5;
  105.  
  106.          for(int var6 = 0; var6 < var5; ++var6) {
  107.             for(int var7 = 0; var7 < var4; ++var7) {
  108.                this.osg.drawImage(this.bkImage, var7 * var2, var6 * var3, this);
  109.             }
  110.          }
  111.       }
  112.  
  113.       for(this.field_0 = 0; this.field_0 < this.numSegments; ++this.field_0) {
  114.          this.osg.setColor(this.colors[this.field_0]);
  115.          if (this.mode == 0) {
  116.             if (!this.showCircles) {
  117.                this.osg.fillRect(this.currentX[this.field_0], this.currentY[this.field_0], this.blockWidth, this.blockHeight);
  118.             } else {
  119.                this.osg.fillOval(this.currentX[this.field_0], this.currentY[this.field_0], this.blockWidth, this.blockHeight);
  120.             }
  121.          } else if (!this.showCircles) {
  122.             this.osg.fillRect(this.currentX[this.field_0], this.currentY[this.field_0], this.blockWidth, this.blockHeight);
  123.          } else {
  124.             this.osg.fillOval(this.currentX[this.field_0], this.currentY[this.field_0], this.blockWidth, this.blockHeight);
  125.          }
  126.       }
  127.  
  128.       this.UpdatePositions();
  129.       var1.drawImage(this.osImage, 0, 0, (ImageObserver)null);
  130.    }
  131.  
  132.    public void run() {
  133.       try {
  134.          while(true) {
  135.             ((Component)this).repaint();
  136.             Thread.sleep((long)this.delay);
  137.          }
  138.       } catch (InterruptedException var1) {
  139.       }
  140.    }
  141.  
  142.    public void UpdatePositions() {
  143.       for(int var1 = 0; var1 < this.numSegments; ++var1) {
  144.          if (this.mode == 0) {
  145.             int[] var10000 = this.currentX;
  146.             var10000[var1] += (this.blockWidth + this.blockSpacing) * this.direction[var1];
  147.             if (this.direction[var1] == 1) {
  148.                if (this.currentX[var1] >= ((Component)this).size().width - this.blockWidth) {
  149.                   this.direction[var1] = -1;
  150.                   this.currentX[var1] = ((Component)this).size().width - this.blockWidth;
  151.                }
  152.             } else if (this.currentX[var1] <= 0) {
  153.                this.direction[var1] = 1;
  154.                this.currentX[var1] = 0;
  155.             }
  156.          } else {
  157.             int[] var2 = this.currentY;
  158.             var2[var1] += (this.blockHeight + this.blockSpacing) * this.direction[var1];
  159.             if (this.direction[var1] == 1) {
  160.                if (this.currentY[var1] >= ((Component)this).size().height - this.blockHeight) {
  161.                   this.direction[var1] = -1;
  162.                   this.currentY[var1] = ((Component)this).size().height - this.blockHeight;
  163.                }
  164.             } else if (this.currentY[var1] <= 0) {
  165.                this.direction[var1] = 1;
  166.                this.currentY[var1] = 0;
  167.             }
  168.          }
  169.       }
  170.  
  171.    }
  172.  
  173.    public Dimension minimumSize() {
  174.       return this.mode == 0 ? new Dimension(100, 20) : new Dimension(20, 100);
  175.    }
  176.  
  177.    public Dimension preferredSize() {
  178.       return this.mode == 0 ? new Dimension(100, 20) : new Dimension(20, 100);
  179.    }
  180.  
  181.    public synchronized void reshape(int var1, int var2, int var3, int var4) {
  182.       super.reshape(var1, var2, var3, var4);
  183.       this.osImage = null;
  184.       this.osg = null;
  185.       if (this.mode == 0) {
  186.          this.blockHeight = var4;
  187.       } else {
  188.          this.blockWidth = var3;
  189.       }
  190.  
  191.       this.currentX = new int[this.numSegments];
  192.       this.currentY = new int[this.numSegments];
  193.       this.direction = new int[this.numSegments];
  194.       if (this.mode == 0) {
  195.          this.increment = var4;
  196.       } else {
  197.          this.increment = var3;
  198.       }
  199.  
  200.       for(int var5 = 0; var5 < this.numSegments; ++var5) {
  201.          if (this.mode == 0) {
  202.             this.currentX[var5] = -((this.numSegments - 1 - var5) * (this.blockWidth + this.blockSpacing));
  203.             this.currentY[var5] = 0;
  204.          } else {
  205.             this.currentX[var5] = 0;
  206.             this.currentY[var5] = -((this.numSegments - 1 - var5) * (this.blockHeight + this.blockSpacing));
  207.          }
  208.  
  209.          this.direction[var5] = 1;
  210.       }
  211.  
  212.       this.red = this.theColor.getRed();
  213.       this.green = this.theColor.getGreen();
  214.       this.blue = this.theColor.getBlue();
  215.       this.redStep = this.red / this.numSegments;
  216.       this.greenStep = this.green / this.numSegments;
  217.       this.blueStep = this.blue / this.numSegments;
  218.       this.colors = new Color[this.numSegments];
  219.       if (!this.sineCalc) {
  220.          for(this.field_0 = 1; this.field_0 <= this.numSegments; ++this.field_0) {
  221.             this.colors[this.field_0 - 1] = new Color(this.redStep * this.field_0, this.greenStep * this.field_0, this.blueStep * this.field_0);
  222.          }
  223.  
  224.       } else {
  225.          double var6 = (Math.PI / 2D) / (double)this.numSegments;
  226.  
  227.          for(this.field_0 = 1; this.field_0 <= this.numSegments; ++this.field_0) {
  228.             double var11 = Math.sin(var6 * (double)this.field_0);
  229.             int var8 = (int)((double)this.red * var11);
  230.             int var9 = (int)((double)this.green * var11);
  231.             int var10 = (int)((double)this.blue * var11);
  232.             this.colors[this.field_0 - 1] = new Color(var8, var9, var10);
  233.          }
  234.  
  235.       }
  236.    }
  237. }
  238.